cmake_minimum_required (VERSION 3.10)

project(example_protobuf)

# 包含FindProtobuf模块
include(FindProtobuf)

# 查找Protobuf包
find_package(Protobuf QUIET)
find_package(glog QUIET)

if(Protobuf_FOUND AND glog_FOUND)
    message(STATUS "build ${PROJECT_NAME}")

    # 编译proto文件，默认生成路径在 ${CMAKE_CURRENT_BINARY_DIR} 目录下
    protobuf_generate_cpp(PROTO_SRC PROTO_HEADERS proto/BaseConfig.proto)

    # 引入生成的 proto 头文件目录
    include_directories(${CMAKE_CURRENT_BINARY_DIR})

    aux_source_directory(. DIR_SRCS)
    add_executable(${PROJECT_NAME} ${DIR_SRCS} ${PROTO_SRC} ${PROTO_HEADERS})

    target_link_libraries(${PROJECT_NAME} Threads::Threads)
    target_link_libraries(${PROJECT_NAME} glog::glog)
    target_link_libraries(${PROJECT_NAME} ${Protobuf_LIBRARIES})
endif()